package com.abigdreamer.im.client.module.messageProcess;

import com.abigdreamer.im.client.module.main.EIMMainFrame;
import com.abigdreamer.im.client.module.main.headtree.TreeScrollPane;
import com.abigdreamer.im.client.ui.trayIcon.EIMTrayIcon;
import com.abigdreamer.im.message.BaseMessage;
import com.abigdreamer.im.message.MessageType;
import com.abigdreamer.im.message.SysMessage;

public class SysMessageProcess implements IMessageProcess {

	public void processMessage(BaseMessage message) {
		SysMessage sysMsg = (SysMessage) message;
		EIMTrayIcon trayIcon = EIMTrayIcon.getInStance();
		trayIcon.addRevedMessage(message);
		trayIcon.showIcon(message.getMsgType());
		trayIcon.setGetMsg(true);
		processSysMessage(sysMsg);

	}

	private void processSysMessage(SysMessage sysMsg) {
		int msgContentType = sysMsg.getMsgContentType();
		final String srcQQ = sysMsg.getSrcQQ();
		switch (msgContentType) {
		case MessageType.SysMessage_Online:
			java.awt.EventQueue.invokeLater(new Runnable() {
				public void run() {
					TreeScrollPane tree = EIMMainFrame.getInstance().getFriendTree();
					tree.changUserSate(srcQQ, true);
				}
			});
			break;
		case MessageType.SysMessage_Exit:
			java.awt.EventQueue.invokeLater(new Runnable() {
				public void run() {
					TreeScrollPane tree = EIMMainFrame.getInstance().getFriendTree();
					tree.changUserSate(srcQQ, false);
				}
			});
			break;
		}
	}
}
